<?php
	/**
	 * 获取玩家个人信息
	 */
    class PersonalInfo extends APIBase {
		
		public $tag = "PersonalInfo";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic() {
			$uid = $this->uid;
			$userinfo = $this->data_redis->hMget('hu:'.$uid,array('name','sex','point','avater_url','accid'));
			$matchdata = $this->data_redis->hGetAll('hu:'.$uid.':match');
			if(!empty($matchdata)){
			    $totalgames = (int)$matchdata['win_count']+(int)$matchdata['lose_count'];//总局数
			    $highest_winning_streak = (int)$matchdata['highest_winning_streak'];//最高连胜
				$winning_streak = (int)$matchdata['winning_streak'];//连胜
			    if((int)$totalgames!=0){
				    $ratewinning = round((((int)$matchdata['win_count'] / (int)$totalgames) * 100)).'%';
			    }else{
				    $ratewinning = 0;
			    }
				if($winning_streak > $highest_winning_streak){
					$highest_winning_streak = $winning_streak;
				}
			    $info = array('uid'=>$uid,'name'=>filter_emoji($userinfo['name']),'sex'=>$userinfo['sex'],'avater_url'=>$userinfo['avater_url'],'point'=>$userinfo['point'],'accid'=>$userinfo['accid'],
			    'totalgames'=>$totalgames,'highest_winning_streak'=>$highest_winning_streak,'ratewinning'=>$ratewinning);
                $this->returnData($info);
			}else{
				$this->returnError(301,'参数有误！');
			}			
		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
